﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace WindowsGame4
{
    class AIInterface
    {
        static private AIInterface aiInterface = null;
        private EventManager eventManager;
        private EventEmitter eventEmitter;
        private AIInterface()
        {
            eventManager = EventManager.getInstance();
            eventEmitter = EventEmitter.getInstance();
        }

        static public AIInterface getInstance()
        {
            if (aiInterface == null)
                aiInterface = new AIInterface();
            return aiInterface;
        }

        public void update()
        {
            // Send deferred messages
            eventEmitter.sendDelayedMessages();
            // Update all objects
            eventManager.update();
        }
        public void reset()
        {
            eventEmitter.reset();
            eventManager.reset();
        }
        public void deleteObject(String id)
        {
            eventManager.deleteAIObject(id);
        }

        public void registerObject(String id, AIObject.TypeAIObject type)
        {
            switch(type)
            {
                case AIObject.TypeAIObject.AIProjectile:
                    {
                      //  System.Console.WriteLine("Register AIProjectile: " + id);
                        // Create AIObject
                        AIObject aiObject = new AIProjectile(id,type);
                        // Register object
                        eventManager.registerAIObject(aiObject);
                        break;
                    }
                case AIObject.TypeAIObject.AIEnemy:
                    {
                        //System.Console.WriteLine("Register AIEnemy: " + id);
                        // Create AIObject
                        AIObject aiObject = new AIEnemy(id, type);
                        // Register object
                        eventManager.registerAIObject(aiObject);
                        break;
                    }
                case AIObject.TypeAIObject.AIPlayer:
                    {
                        //System.Console.WriteLine("Register AIPlayer: " + id);
                        // Create AIObject
                        AIObject aiObject = new AIPlayer(id, type);
                        // Register object
                        eventManager.registerAIObject(aiObject);
                        break;
                    }
                case AIObject.TypeAIObject.AIBomb:
                    {
                        //System.Console.WriteLine("Register AIObject");
                        // Create AIObject
                        AIObject aiObject = new AIBomb(id, type);
                        // Register object
                        eventManager.registerAIObject(aiObject);
                        break;
                    }
                case AIObject.TypeAIObject.AIExplosion:
                    {
                       // System.Console.WriteLine("Register AIObject");
                        // Create AIObject
                        AIObject aiObject = new AIExplosion(id, type);
                        // Register object
                        eventManager.registerAIObject(aiObject);
                        break;
                    }
            }
        }
    }
}